import type { AxiosRequestConfig } from 'axios';
import axios from 'axios';
import { HttpsProxyAgent } from 'https-proxy-agent';
import minimist from 'minimist';

import { Swagger2Js } from './swagger2code';

const argv = minimist(process.argv.slice(2));
// http代理
if (argv.agent) {
  axios.defaults.httpAgent = new HttpsProxyAgent(argv.agent);
}

interface SwaggerOption {
  import: string;
  requestName: string;
  path: string;
  swagger: AxiosRequestConfig;
}

/**
 * 根据swagger 生成js请求文件
 */
const options: SwaggerOption[] = [
  // swagger接口
  {
    import: "import {fireRequest as request} from '@/utils/request';",
    requestName: 'request',
    path: 'src/genapi/fireProduct',
    swagger: {
      url: 'http://192.168.1.210:8988/fireProduct/v2/api-docs',
    },
  },
];

async function main() {
  const promises = options.map((option) => {
    const swagger = new Swagger2Js(option);
    return swagger.gen();
  });
  await Promise.all(promises);
}

await main();
